using Game;
using GameEntitySystem;
using TemplatesDatabase;

namespace SCIENEW {
    /// <summary>
    /// 所有引擎类组件都要继承此抽象类，此抽象类为引擎个体与引擎动力系统的桥梁，不继承则无法正常使用引擎
    /// </summary>
    public abstract class ComponentEngine : ComponentInventoryTankBase, IEngineComponent {
        public ComponentBlockEntity m_componentBlockEntity;
        public SubsystemEnginePower m_subsystemEnginePower;

        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
            base.Load(valuesDictionary, idToEntityMap);
            m_componentBlockEntity = Entity.FindComponent<ComponentBlockEntity>(true);
            m_subsystemEnginePower = Project.FindSubsystem<SubsystemEnginePower>(true);
        }

        public virtual bool IsPowering() => false;

        public override void OnEntityAdded() {
            base.OnEntityAdded();
            m_subsystemEnginePower.Add(m_componentBlockEntity.Coordinates, this);
        }

        public override void OnEntityRemoved() {
            base.OnEntityRemoved();
            m_subsystemEnginePower.Remove(m_componentBlockEntity.Coordinates);
        }
    }
}